home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11010 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.1 KB

  1. Path: in1.uu.net!interaccess!usenet
  2. From: brianmcg@interaccess.com (Brian V. McGroarty)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help ! Please help me solve the problem
  5. Date: 21 Mar 1996 14:13:48 GMT
  6. Organization: Internet Squire
  7. Message-ID: <4iro6s$2e9@nntp.interaccess.com>
  8. References: <4iltc9$3sa@ctylnk.cityu.edu.hk>
  9. Reply-To: brianmcg@interaccess.com
  10. NNTP-Posting-Host: d222.nhe.interaccess.com
  11. X-Newsreader: Internet Squire 1.20
  12.  
  13. Note that much of your post is Intel '86 specific.  You may get better
  14. results on future questions if you follow up in an MS-DOS programming
  15. group. /* not a flame */
  16.  
  17.  
  18. To call your old function, you will need to first store the vector to the
  19. old function.  With several MS-DOS compilers, I have used:
  20.  
  21. void interrupt ( *oldInterruptFunction )();
  22.  
  23. void interrupt InterruptFunction()
  24. {
  25.     /* do stuff */
  26.  
  27.     oldInterruptFunction(); /* call old function */
  28. }
  29.  
  30. void InstallRoutine()
  31. {
  32.     oldInterruptFunction= VectorGetRoutine( 13 );
  33.     VectorSetRoutine( NewInterruptFunction, 13 );
  34. }
  35.  
  36.  
  37. If you find that you cannot see your data, consider declaring the data as
  38. "far" or "huge" in order to avoid the implicit data segment.  If your
  39. compiler doesn't restore the DS on return, you should store your DS in a
  40. far data item and store and restore it, i.e.
  41.  
  42. short int far myDS;
  43.  
  44. void Installer()
  45. {
  46.     short int fetchDS; /* don't assume format of far ptr */
  47.  
  48.     asm {
  49.         mov ax,ds
  50.         mov fetchDS, ax
  51.     }
  52.     myDS= fetchDS;
  53.  
  54.     /* install interrupt vector here */
  55. }
  56.  
  57. void interrupt InterruptRoutine()
  58. {
  59.     short int holdDS, fetchDS;
  60.  
  61.     asm { /* fetch original DS */
  62.         mov ax,ds
  63.         mov holdDS, ax
  64.     }
  65.     fetchDS= myDS;
  66.     asm {
  67.         mov ax, fetchDS
  68.         mov ds, ax
  69.     }
  70.  
  71.     /* do your work here */
  72.  
  73.     asm { /* restore interrupt DS */
  74.         mov ax, holdDS
  75.         mov ds, ax
  76.     }
  77.  
  78.     oldInterruptFunction();
  79. }
  80.  
  81. Note that you may need to explicitly set ES too!
  82.  
  83.  
  84. Maxeller wrote:
  85. >  I want to write a disk cache program and so must place my new interrupt
  86. >  point into interrupt vector 13 which points to my new function. 
  87.  
  88. >  Please take a look at my simple test program please:
  89.  
  90. >  unsign long old_int_pointer;
  91.  
  92. >  new_int_function()
  93. >     {
  94.      
  95.        
  96. >      /* just jump to old_int_pointer  which read from disk 
  97. >         because it is a test program so nothing others is done */
  98.  
  99. >     }
  100.  
  101. >  main()
  102. >     {
  103. >      /* save old int13 pointer into old_int_pointer
  104. >         using int21h ax=3513 */
  105.       
  106. >      /* put address of new_int_function() into vector 13 area
  107. >         using int21h ax=2513 */
  108.  
  109. >      /* TSR function goes here */
  110.  
  111. >     }
  112.  
  113. > Save and put new interrupt address and TSR is OK.
  114.  
  115. > However when disk reading is involved, it hangs.
  116.  
  117. > My problem is : 
  118. >      1) what code should write so it can jump to my 
  119. >         old_int_pointer. I have though for a long time!! :-(
  120. >      2) I am afraid that when control is passed to new_int_function,
  121. >         it can not retrieve values such as old_int_pointer because
  122. >         the segment register may not match as that in my program.
  123.  
  124. ---
  125. Brian Valters McGroarty -- brianmcg@bix.com
  126. phone/fax (847) 439-7714
  127.